package com.itgone.easyblog.controller;


import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.itgone.easyblog.service.image.impl.AliyunFileService;
import com.itgone.easyblog.service.image.impl.QnyFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * 图片上传下载控制层
 *
 * @author Earlman
 * @since 2023-03-24 13:54:19
 */
@Api(description = "图片上传下载控制层")
@RestController
@RequestMapping("image")
public class ImageController extends ApiController {

    /**
     * 服务对象
     */
    @Resource
    private QnyFileService qnyFileService;

    @Resource
    private AliyunFileService aliyunFileService;


    /**
     * 图片上传
     *
     * @param imageFile 图片文件
     * @return 新增结果
     */
    @ApiOperation("图片上传")
    @PostMapping("upload")
    public R upload(MultipartFile imageFile) {
        return success(qnyFileService.upload(imageFile));
    }

    @ApiOperation("图片上传")
    @PostMapping("upload-aliyun")
    public R uploadAliyun(MultipartFile imageFile) {
        return success(aliyunFileService.upload(imageFile));
    }


    @ApiOperation("图片上传")
    @PostMapping("upload-qniiu")
    public R uploadQiniu(MultipartFile imageFile) {
        return success(qnyFileService.upload(imageFile));
    }

    /**
     * 图片删除
     *
     * @param url 图片文件url路径
     * @return 删除结果
     */
    @ApiOperation("图片上传")
    @DeleteMapping
    public R upload(@RequestParam String url) {
        return success(qnyFileService.deleteByUrl(url));
    }
}

